package com.ericsson.eritask.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ericsson.eritask.dao.impl.SaveTaskDaoImpl;
import com.ericsson.eritask.dto.ProjectDTO;
import com.ericsson.eritask.dto.ReminderDTO;
import com.ericsson.eritask.dto.TaskDTO;
import com.ericsson.eritask.dto.UserTaskDTO;
import com.ericsson.eritask.service.AssignTaskService;

@Service
public class AssignTaskServiceImpl implements AssignTaskService{

	@Autowired
	SaveTaskDaoImpl saveTaskDaoImpl;
	
	public void setSaveTaskDaoImpl(SaveTaskDaoImpl saveTaskDaoImpl) {
		this.saveTaskDaoImpl = saveTaskDaoImpl;
	}
	
	public List<TaskDTO> readTask()
	{
		List<TaskDTO> l = new ArrayList<TaskDTO>();
		return l;
	}
	public boolean saveTask(ProjectDTO projDto, TaskDTO taskDto, ReminderDTO reminderDTO) throws Exception
	{
		boolean flag = false;
		/*taskDto.setSubject("Do the task poc");// later taskDto.setSubject(taskVo.getSubject());
		taskDto.setStartDate(convertStringToDate("26-02-2016"));
		taskDto.setDueDate(convertStringToDate("03-03-2016"));
		taskDto.setPriority("1");
		taskDto.setStatus("WIP");
		taskDto.setCompletepart(20);*/
		/*taskDto.setSubject(taskVo.getSubject());
		taskDto.setCompletepart(taskVo.getCompletepart());
		taskDto.setDueDate(taskVo.getDueDate());
		taskDto.setPriority(taskVo.getPriority());
		taskDto.setReminder(taskVo.getReminder());
		taskDto.setStartDate(taskVo.getStartDate());
		taskDto.setStatus(taskVo.getStatus());*/
		
		System.out.println("in saveTask-----------------");
		
		flag = saveTaskDaoImpl.insertTask(projDto, taskDto, reminderDTO);
		System.out.println("----------------------in service---------------------------------");
		System.out.println("Project id = "+projDto.getProjectId());
		System.out.println("Project Name = "+projDto.getProjectName());
		return flag;
	}
	public void deleteTaskGroup(TaskDTO taskVo)
	{
		
	}
	
	public Date convertStringToDate(String s)
	{
		SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
		Date date;
		try
		{
			date = formatter.parse(s);
			System.out.println(date);
			System.out.println(formatter.format(date));
			return date;
		}
		catch(ParseException p)
		{
			p.printStackTrace();
			return null;
		}
		
	}

	@Override
	public boolean saveUserTask(ProjectDTO projDto, TaskDTO taskDto, ReminderDTO reminderDTO, UserTaskDTO userTaskDTO)
			throws Exception {
		boolean flag = false;
		
		System.out.println("in saveTask-----------------");
		
		flag = saveTaskDaoImpl.insertUserTask(projDto, taskDto, reminderDTO,userTaskDTO);
		System.out.println("----------------------in service---------------------------------");
		System.out.println("Project id = "+projDto.getProjectId());
		System.out.println("Project Name = "+projDto.getProjectName());
		return flag;
	}
}
